<?php
/**
 * DBERP 进销存系统
 *
 * ==========================================================================
 * @link      http://www.dberp.net/
 * @copyright 北京珑大钜商科技有限公司，并保留所有权利。
 * @license   http://www.dberp.net/license.html License
 * ==========================================================================
 *
 * @author    静静的风 <baron@loongdom.cn>
 *
 */

namespace Admin\Repository;

use Admin\Entity\Region;
use Doctrine\ORM\EntityRepository;

class RegionRepository extends EntityRepository
{
    /**
     * 获取地区对用的字符串
     * @param $regionPath
     * @return string
     */
    public function getRegionStr($regionPath): string
    {
        $query = $this->getEntityManager()->createQueryBuilder();
        $query->select('r.regionName')
            ->from(Region::class, 'r')
            ->where($query->expr()->in('r.regionId', $regionPath))
            ->orderBy('r.regionId', 'ASC');

        $regionArray = $query->getQuery()->getArrayResult();
        if (empty($regionArray)) {
            return '';
        }

        $regionStr = '';
        foreach ($regionArray as $value) {
            $regionStr .= $value['regionName'];
        }

        return $regionStr;
    }
}